package com.lemon.smartsafetynew.ui.adapter.patrol;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolChildItemDetailHistoryVo;

import java.util.ArrayList;
import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/8/23.
 */

public class PatrolCheckItemHistoryAdapter extends LemonRcvAdapter<SafePatrolChildItemDetailHistoryVo> {

    private RecyclerTClickListener<SafePatrolChildItemDetailHistoryVo> mListener;


    public PatrolCheckItemHistoryAdapter(@Nullable List<SafePatrolChildItemDetailHistoryVo> data,
                                         RecyclerTClickListener<SafePatrolChildItemDetailHistoryVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new CheckItem();
    }


    private class CheckItem implements AdapterItem<SafePatrolChildItemDetailHistoryVo> {

        private TextView checkItemTitleTv;
        private TextView checkItemDescribeTv;

        private RadioButton successRadioBtn;
        private RadioButton failRadioBtn;

        private LinearLayout remarkLayout;
        private LinearLayout checkItemLayout;

        private SafePatrolChildItemDetailHistoryVo mData;
        private int mPosition;

        @Override
        public int getLayoutResId() {
            return R.layout.item_safe_patrol_check_item;
        }

        @Override
        public void bindViews(View root) {

            checkItemTitleTv = (TextView) root.findViewById(R.id.check_item_title_tv);
            checkItemDescribeTv = (TextView) root.findViewById(R.id.check_item_describe_tv);

            successRadioBtn = (RadioButton) root.findViewById(R.id.success_radio_btn);
            failRadioBtn = (RadioButton) root.findViewById(R.id.fail_radio_btn);

            remarkLayout = (LinearLayout) root.findViewById(R.id.remark_layout);
            checkItemLayout = (LinearLayout) root.findViewById(R.id.check_item_layout);

        }

        @Override
        public void setViews() {

            checkItemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });

        }

        @Override
        public void handleData(SafePatrolChildItemDetailHistoryVo childItemDetailHistoryVo, int position) {

            mPosition = position;
            mData = childItemDetailHistoryVo;

            remarkLayout.setVisibility(View.GONE);

            checkItemTitleTv.setText(childItemDetailHistoryVo.getFlow_name());
            checkItemDescribeTv.setText(childItemDetailHistoryVo.getCheck_way());

            if("green_mark".equals(childItemDetailHistoryVo.getMark_code())) {
                successRadioBtn.setVisibility(View.VISIBLE);
                successRadioBtn.setChecked(true);
                successRadioBtn.setText(childItemDetailHistoryVo.getConclusion_name());

                failRadioBtn.setVisibility(View.GONE);
            } else {
                failRadioBtn.setVisibility(View.VISIBLE);
                failRadioBtn.setChecked(true);
                failRadioBtn.setText(childItemDetailHistoryVo.getConclusion_name());

                successRadioBtn.setVisibility(View.GONE);
            }

        }
    }
}